package com.pro01.backend.service;

import com.pro01.backend.mapper.UserPromotionMapper;
import com.pro01.backend.pojo.PageResult;
import com.pro01.backend.pojo.UserPromotion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class UserPromotionService {

    @Autowired
    private UserPromotionMapper userPromotionMapper;

    // 用户查看自己的促销奖励
    public PageResult<UserPromotion> getMyPromotionRewards(Long userId, int pageNum, int pageSize) {
        int offset = (pageNum - 1) * pageSize;
        List<UserPromotion> records = userPromotionMapper.getUserPromotionsPaged(userId, offset, pageSize);
        int total = userPromotionMapper.countUserPromotions(userId);

        PageResult<UserPromotion> result = new PageResult<>();
        result.setTotal(total);
        result.setRecords(records);
        return result;
    }

    // 管理员查看所有促销奖励
    public PageResult<Map<String, Object>> getAllUserPromotions(int pageNum, int pageSize) {
        int offset = (pageNum - 1) * pageSize;
        List<Map<String, Object>> records = userPromotionMapper.getAllUserPromotionsPaged(offset, pageSize);
        int total = userPromotionMapper.countAllUserPromotions();

        PageResult<Map<String, Object>> result = new PageResult<>();
        result.setTotal(total);
        result.setRecords(records);
        return result;
    }

}
